import Taro from '@tarojs/taro';

export const Storage = {
  /**
   * 获取持久化内容
   * @param key
   */
  getItem: (key: string) => {
    return Taro.getStorageSync(key);
  },

  /**
   * 内容持久化
   * @param key
   * @param value
   */
  setItem: (key: string, value: any) => {
    Taro.setStorageSync(key, value);
  },
};

export const Toast = {
  info: (message: string) => {
    Toast.showToast(message, 'none');
  },

  error: (message: string) => {
    Toast.showToast(message, 'error');
  },

  success: (message: string) => {
    Toast.showToast(message, 'success');
  },

  showToast: (
    message: string,
    icon?: 'success' | 'error' | 'loading' | 'none',
  ) => {
    Taro.showToast({
      title: message,
      icon: icon,
    });
  },
};
